<?php
require_once "weixin/WxpayHelper.php";
class Wxpay extends WxpayHelper{
    public function __construct($wx)
    {
        parent::__construct($wx);
    }


    //调用统一下单接口生成预支付订单并把数据返回给APP
    public function pay_order($total_fee, $out_trade_no, $subject)
    {
        $wxpayandroid = new \WxpayHelper;  //实例化微信支付类
        $res          = $wxpayandroid->Weixinpayandroid($total_fee, $out_trade_no, $subject); //调用weixinpay方法
        if ($res['errorCode'] != 0) {
            return ['code' => false, 'msg' => $res['errorMsg']];
        } else {
            $res['responseData']['order_no'] = $out_trade_no;
            return ['code' => true, 'data' => $res['responseData'], 'msg' => '请求成功'];
        }
    }


    /**
     * 退款
     * @param $total 总金额
     * @param $money 退款金额
     * @param $out_trade_no
     * @param $subject 备注
     * @return mixed
     * @throws Exception
     */
    public function refund($money,$out_trade_no, $subject,$total)
    {
        $res = $this->refund($money,$out_trade_no, $subject,$total); //调用weixinpay方法
        if($res['return_code'] == 'SUCCESS'){
            if($res['result_code'] == 'SUCCESS'){
                return ['code'=>true,'msg'=>'退款成功'];
            }else{
                return ['code'=>false,'msg'=>$res['err_code_des']];
            }
        } else {
            return ['code'=>false,'msg'=>'退款接口请求失败'];
        }
    }


}
